<?php
namespace Blog\Controller;

use Common\Controller\AdminbaseController;


class IndexmyController extends AdminbaseController
{


    function index()
    {//游学网站
        $this->display();
    }

    function login()
    {//用户组
        $where = array();
        $request = I('request.');

        if (!empty($request['uid'])) {
            $where['id'] = intval($request['uid']);
        }

        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];
            $keyword_complex = array();
            $keyword_complex['user_login'] = array('like', "%$keyword%");
            $keyword_complex['user_nicename'] = array('like', "%$keyword%");
            $keyword_complex['user_email'] = array('like', "%$keyword%");
            $keyword_complex['_logic'] = 'or';
            $where['_complex'] = $keyword_complex;
        }

        $users_model = M("User");

        $count = $users_model->where($where)->count();
        $page = $this->page($count, 20);

        $list = $users_model
            ->where($where)
            ->order("create_time DESC")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();

        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));

        $this->display();
    }

    // 管理员删除
    function delete()
    {
        $id = I('get.id', 0, 'intval');
        if ($this->users_model->delete($id) !== false) {
            M("user")->where(array("id" => $id))->delete();
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }

    function Countrylist()
    {//游学国家列表
        $this->display();
    }

    function StudySeries()
    {//游学系列
        $this->display();
    }

    function PersonalCenter()
    {//个人中心
        $this->display();
    }

    function Departuretime()
    {//出发时期
        $this->display();
    }

    function CityGroup()
    {//出团城市
        $where = array();
        $request = I('request.');
        if (!empty($request['city_id'])) {
            $where['city_id'] = intval($request['city_id']);
        }

        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];
            $keyword_complex = array();
            $keyword_complex['city|dq'] = array('like', "%$keyword%");
            $where['_complex'] = $keyword_complex;
        }
        $users_model = M("ctcity");

        $count = $users_model->join('cmf_ctcity join cmf_type on cmf_ctcity.dq_id=cmf_type.quyu_id')->where($where)->count();
        $page = $this->page($count, 20);
        $list = $users_model
            ->join('cmf_ctcity join cmf_type on cmf_ctcity.dq_id=cmf_type.quyu_id')
            ->where($where)
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();

        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));

        $this->display();
    }

    function Linedetails()
    {//线路详情
        $this->display();
    }

    function Travelsafety()
    {//个人中心->游学安全视频
        $this->display();
    }

    function Appointment()
    {//个人中心->预约报名
        $this->display();
    }

    function Offlinepayment()
    {//个人中心->线下订单支付/绑定
        $this->display();
    }

    function Myorder()
    {//个人中心->我的订单
        $this->display();

    }

    function addcity()
    {//添加城市
        $cmf_type = M('type');
        $fh = $cmf_type->select();
        $this->assign('fh', $fh);

        $this->display();
    }

    function adduser()
    {//添加用户

        $this->display();
    }

    function add_user()
    {
        $user_login = I('user_login');
        $user_pass = md5(md5(I('user_pass')) . 'ff');
        $user_email = I('user_email');
        $ctime = date('y-m-d H:i:s');

        if (!empty($user_login)) {
            $cmf_user = M("User");
            $xt = $cmf_user->where("user_login=$user_login")->find();
            if (!empty($xt)) {
                $this->ajaxReturn(333);
            } else {
                if (!empty($user_login) && !empty($user_pass) && !empty($user_email)) {
                    $Adddata['user_login'] = $user_login;
                    $Adddata['user_pass'] = $user_pass;
                    $Adddata['user_email'] = $user_email;
                    $Adddata['create_time'] = $ctime;
                    $Adddata['user_nicename'] = $user_login;
                    if (!empty($Adddata)) {
                        $cmf_user->add($Adddata);
                        $this->ajaxReturn(1111);
                    }
                } else {
                    $this->ajaxReturn(2222);
                }
            }
        }
    }

    function modify()
    {
        $id = I('id');
        $user_login = I('user_login');
        $user_pass = md5(md5(I('user_pass')) . 'ff');
        $user_email = I('user_email');
        if (!empty($user_login)) {
            $cmf_user = M('User');
            $xt = $cmf_user->where("user_login=$user_login")->find();
            if (!empty($xt)) {
                $this->ajaxReturn(333);
            } else {
                if (!empty($id) && !empty($user_login) && !empty($user_pass) && !empty($user_email)) {
                    $data['user_login'] = $user_login;
                    $data['user_pass'] = $user_pass;
                    $data['user_email'] = $user_email;
                    $data['user_nicename'] = $user_login;
                    $cmf_user->where("id=$id")->save($data);
                    $this->ajaxReturn(111);
                } else {
                    $this->ajaxReturn(222);
                }
            }
        }


    }

    function dele()
    {
        $id = I('id');
        if (!empty($id)) {
            $cmf_user = M("User");
            $cmf_user->where("id=$id")->delete();
            $this->ajaxReturn(111);
        } else {
            $this->ajaxReturn(222);
        }
    }

    function addcity1()
    {
        $cmf_ctcity = M('ctcity');
        $city = I('city');
        $dq1 = I('dq1');

        if (!empty($city)) {
            $condition['city'] = $city;
            $fh = $cmf_ctcity->where($condition)->find();
            if (!empty($fh)) {
                $this->ajaxReturn(333);
            } else {
                if (!empty($dq1)) {
                    $cmf_type = M('type');
                    $condition['dq'] = $dq1;
                    $fh = $cmf_type->where($condition)->select();
                    $id = $fh[0]['quyu_id'];
                    if (!empty($city) && !empty($id)) {

                        $data['city'] = $city;
                        $data['dq_id'] = $id;
                        $cmf_ctcity->add($data);
                        $this->ajaxReturn(111);

                    } else {
                        $this->ajaxReturn(222);
                    }
                }
            }
        }


    }

    function city_sc()
    {
        $id = I('id');
        if (!empty($id)) {
            $cmf_user = M("ctcity");
            $cmf_user->where("city_id=$id")->delete();
            $this->ajaxReturn(111);
        } else {
            $this->ajaxReturn(222);
        }
    }


}

